/// <reference path="../_all.ts" />

module Application.Services {

    export class ActionService implements Application.Interfaces.Services.IActionService {
        _actionClass: Application.Resources.IActionClass;
        _actionServerClass: ng.resource.IResourceClass;

        public static $inject = [
            '$http',
            '$resource',
        ];

        constructor(public Http: ng.IHttpService, public Resource: ng.resource.IResourceService) {
            this._actionClass = <Application.Resources.IActionClass> this.Resource(Application.Services.ServiceUtility.GetServiceURL('actions/:id'), null, null);
            this._actionServerClass = <Application.Resources.IActionClass> this.Resource(Application.Services.ServiceUtility.GetServiceURL('actions/servers/:id'), null, null);
        }

        public GetActions(callback: Function) {
            this._actionClass.query(
                function (data: any, h: any) {
                    callback(data, null);
                },
                function (err: any) {
                    callback(null, err);
                });
        }

        public GetServerActions(server_id: number, callback: Function) {
            this._actionServerClass.query({ id: server_id },null,
                function (data: any, h: any) {
                    callback(data, null);
                },
                function (err: any) {
                    callback(null, err);
                });
        }

        public CloseAction(action: Application.Resources.IAction, callback: Function) {
            this._actionClass.delete({ id: action.action_id }, null,
                function (data: any, h: any) {
                    callback(data, null);
                },
                function (err: any) {
                    callback(null, err);
                });
        }
    };
}